<%@ page language="java" import="java.util.*,java.net.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page import="java.io.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="styles/basic.css" rel="stylesheet" type="text/css" />
<title>download</title>
</head>

<%	response.setCharacterEncoding("UTF-8");
	request.setCharacterEncoding("UTF-8");
	System.out.println("================lilei============");
	byte[] a = request.getParameter("file").getBytes("ISO-8859-1");
	String filepath = new String(a,"UTF-8");
	System.out.println("============================"+filepath);
	if (filepath != null) {
		OutputStream os = null;
		FileInputStream fis = null;
		try {
			String file = filepath;
			if (!(new File(file)).exists()) {
				System.out.println("没有文件");
				return;
				}
		
			String filename = file.substring(file.lastIndexOf("\\")+1);
			System.out.println("文件名为："+filename);
			os = response.getOutputStream();
			response.setHeader("content-disposition", "attachment;filename=" + new String(filename.getBytes("GBK"), "ISO-8859-1"));
			response.setContentType("application/octet-stream");
			//八进制流 与文件类型无关
			byte temp[] = new byte[1024];
			fis = new FileInputStream(file);
			
			int n = 0;
			while ((n = fis.read(temp)) != -1) {
				os.write(temp, 0, n);
			}
		} catch (Exception e) {
			out.print("出错了");
		} finally {
			if (os != null)
				os.close();
			if (fis != null)
				fis.close();
		}
		
		out.clear();
		out = pageContext.pushBody();
	}
%>

  
   

</html>